package com.hualan.sfzyproject.service;

import com.hualan.sfzyproject.domain.*;
import com.hualan.sfzyproject.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service
public class ConsultantsService {

//    查询所有咨询师和登记表二表查询
    @Autowired
    private ConsultantsAndLevelMapper consultantsAndLevelMapper;
    @Autowired
    private CharityActivityMapper charityActivityMapper;
    public List<ConsultantsAndLevel> selectAllConsultantsAndLevel(int pNum ,int pSize) {
        int pageNum = pNum; // 假设要查询第2页的数据
        int pageSize = pSize; // 每页显示10条数据

        List<ConsultantsAndLevel> paginatedConsultants = consultantsAndLevelMapper.selectAllConsultantsAndLevel((pageNum - 1) * pageSize, pageSize);
        return paginatedConsultants;
    }

//    查询所有咨询师地域
    @Autowired
    private ConsultantsMapper consultantsMapper;
    public List<Consultants>  selectAllConsultantsAddress(){
        return consultantsMapper.selectAllConsultantsAddress();
    }

    public List<Consultants> selectConsultantsByLevel(int consultantLevelId){
        return consultantsMapper.selectConsultantsByLevel(consultantLevelId);
    }
//    查询所有擅长
    @Autowired
    private AreasMapper areasMapper;
    public List<Areas>  selectAllAreas(){
        return areasMapper.selectAreaList();
    }

//    查询所有咨询师等级
    @Autowired
    private ConsultantLevelMapper consultantLevelMapper;
    public List<ConsultantLevel>  selectAllConsultantLevel(){
        return consultantLevelMapper.selectAllConsultantLevel();
    }

//    查询所有咨询师咨询方式
    @Autowired
    private ChargeStandardTypeMapper chargeStandardTypeMapper;
    public List<ChargeStandardType> selectAllChargeStandardType(){
        return chargeStandardTypeMapper.selectAllChargeStandardType();
    }

    public List<Consultants> selectConsultantsByLike1(String like){
        return consultantsMapper.selectConsultantsByLike1(like);
    }

//    ==================================================

//    查询所有咨询师


    public List<Consultants> selectAllConsultants(int pageNo,int pageSize) {
        return consultantsMapper.selectAllConsultants(pageNo,pageSize);
    }

//    模糊查询所有咨询师（后台）
public List<Consultants> selectConsultantsByLike(int offset, int pageSize, String name) {
    return consultantsMapper.selectConsultantsByLike(offset, pageSize, name);
}


//   咨询师擅长查询(后台)
    public List<Areas> selectAreaById(int consultantId) {
        return areasMapper.selectAreaById(consultantId);
    }



//    添加咨询师擅长(后台-添加)
public int insertArea(ConsultantSpecializationArea consultantSpecializationArea){
    return areasMapper.insertArea(consultantSpecializationArea);
}


//    删除咨询师擅长(后台-删除)
    public int deleteAreaById(int consultantId, int areaId){
        return areasMapper.deleteAreaById(consultantId, areaId);
    }




    //    添加咨询师时展示(后台-添加展示)
    public List<Areas> selectAreaList2(){
        return areasMapper.selectAreaList2();
    }


//    查询收费标准管理（后台）
    public List<FeeManagement> selectAllFeeManagement(int consultantId){
        return consultantsMapper.selectAllFeeManagement(consultantId);
    }


//收费类型查询（后台）
    public List<ChargeStandardType> selectChargeStandardType(){
        return consultantsMapper.selectAllChargeStandardType();
    }

//    <!--    删除收费标准-->
    public int deleteFeeManagement(int chargeTypeId, int consultantId){
        return consultantsMapper.deleteFeeManagement(chargeTypeId ,consultantId);
    }


//    添加收费标准
    public int insertChargeStandardAssociation(ChargeStandardAssociation chargeStandardAssociation){
        return consultantsMapper.insertChargeStandardAssociation(chargeStandardAssociation);
    }




    //    ==================================================
//咨询师登录
public int consultantLogin(String name,String password){
    Consultants consultant = consultantsMapper.selectByName(name);

    int i = 0; //用户名/手机号不存在
    if (consultant != null){ // 用户名/手机号存在
        if (password.equals(consultant.getConsultantPassword())){
            i = 1;  // 登录成功
        }else{
            i = -1; //密码错误
        }
    }
    return i;
}

    //咨询师注册
    public int consultantRegister(Consultants consultant){
        return consultantsMapper.insertSelective(consultant);
    }

    //咨询师修改
    public int updateConsultant(Consultants consultant){
        return consultantsMapper.updateByPrimaryKeySelective(consultant);
    }


    //根据咨询师id查询咨询师信息
    public Consultants selectByConsultantId(Long consultantId){
        return consultantsMapper.selectByPrimaryKey(consultantId);
    }

    //    咨询师详情  十表查询!
    public Consultants selectConsultantsDetail(Long id){
        return consultantsMapper.selectConsultantsDetail(id);
    }


    //    六表查筛选
    public List<ConsultantSimple> selectDynamicQueries(ConsultantsDynamicQueries dynamicQueries) {
        // 这里可以添加一些业务逻辑，比如对查询条件进行预处理等
        return consultantsMapper.selectDynamicQueries(dynamicQueries);
    }






//    查询所有咨询师（根据id查询）(咨询师列表)（仅涉及咨询师表与等级表联查）
public List<ConsultantsAndLevel> selectConsultantsAndLevelById(int pNum ,int pSize, int[] consultantIds) {
    int pageNum = pNum; // 假设要查询第2页的数据
    int pageSize = pSize; // 每页显示10条数据
    List<ConsultantsAndLevel> paginatedConsultants = consultantsAndLevelMapper.selectConsultantsAndLevelById((pageNum - 1) * pageSize, pageSize,consultantIds);
    return paginatedConsultants;
    }



}